//
//  LHNavigationController.m
//  play
//
//  Created by zhouLiHuan on 2016/12/9.
//  Copyright © 2016年 zhouLiHuan. All rights reserved.
//

#import "LHNavigationController.h"
#import "UIBarButtonItem+LH.h"

@interface LHNavigationController ()<UINavigationBarDelegate,UIGestureRecognizerDelegate>
@property (nonatomic, weak) UIScreenEdgePanGestureRecognizer *screenEdgePanGestureRecognizer;
@end

@implementation LHNavigationController

+(void)initialize{
 
     // 设置UINavigationBarTheme的主题
    [self setUpNavigationBarTheme];
    
    // 设置UIBarButtonItem的主题
    [self setupUIBarButtonItemTheme];

}



 // 设置UINavigationBarTheme的主题

+(void)setUpNavigationBarTheme {

    UINavigationBar *appearance = [UINavigationBar appearance];
    appearance.translucent = NO;
    
    //设置导航栏颜色
    [appearance setBarTintColor:MianColor];
    //设置文字属性
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = TextBlackColor;
    textAttrs[NSFontAttributeName] = kSystemNavigationTitleFont;
    
    [appearance setTitleTextAttributes:textAttrs];
    

}

// 设置UIBarButtonItem的主题
+(void)setupUIBarButtonItemTheme{

    UIBarButtonItem *appearance = [UIBarButtonItem appearance];
    //normal
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:17*kScaling750];
    [appearance setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    
    NSMutableDictionary *highTextAttrs = [NSMutableDictionary dictionaryWithCapacity:textAttrs];
    highTextAttrs[NSForegroundColorAttributeName] = [UIColor redColor];
    highTextAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:17*kScaling750];
    [appearance setTitleTextAttributes:highTextAttrs forState:UIControlStateHighlighted];
    
    //disable
    NSMutableDictionary *disableTextAttrs = [NSMutableDictionary dictionaryWithCapacity:textAttrs];
    disableTextAttrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    [appearance setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];
    

}

#pragma mark - Setter

- (void)setScreenEdgePanGestureRecognizerEnable:(BOOL)screenEdgePanGestureRecognizerEnable
{
    _screenEdgePanGestureRecognizerEnable = screenEdgePanGestureRecognizerEnable;
    self.screenEdgePanGestureRecognizer.enabled = _screenEdgePanGestureRecognizerEnable;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    id target = self.interactivePopGestureRecognizer.delegate;
    
    UIScreenEdgePanGestureRecognizer *screenEdgePanGestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    
    screenEdgePanGestureRecognizer.edges = UIRectEdgeLeft;
    screenEdgePanGestureRecognizer.delegate = self;
    [self.view addGestureRecognizer:screenEdgePanGestureRecognizer];
    self.screenEdgePanGestureRecognizer = screenEdgePanGestureRecognizer;
    self.interactivePopGestureRecognizer.enabled = NO;
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{

    if (self.viewControllers.count>0) {
        
        viewController.hidesBottomBarWhenPushed = YES;
        //设置导航栏返回按钮样式
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageName:@"Nav_back" highlightImageName:@"Nav_back" target:self action:@selector(back)];
    }
    
    [super pushViewController:viewController animated:YES];

}


-(void)back{

    [self popViewControllerAnimated:YES];

}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{

    //判断导航控制器是否只有一个自控制器 如果只有一个自控制器 肯定是跟控制器
    if (self.childViewControllers.count == 1) {
        
        //b标示用户在跟控制下面 不需要滑动
        return NO;
        
    }

    return YES;
}



@end



















